using System;
using Microsoft.Web.Administration;
using Microsoft.Web.Management.Iis.Client;

namespace Microsoft.Web.Management.Iis.Server
{
    /// <summary>
    /// Provides access to the &lt;configuration&gt;&lt;system.applicationHost&gt;&lt;log/&gt;&lt;/system.applicationHost&gt;&lt;/configuration&gt;
    /// element.
    /// </summary>
    internal sealed class LogConfigurationSection : ConfigurationSection
    {
        /********************************************************************************************
           STATIC FIELDS
         *******************************************************************************************/
        // Child element names
        private const string BinaryLogElement = "centralBinaryLogFile";
        private const string W3CLogElement = "centralW3CLogFile";

        // Child attribute names
        private const string LogModeAttribute = "centralLogFileMode";
        private const string LogInUtf8Attribute = "logInUtf8";

        /********************************************************************************************
           INSTANCE FIELDS
         *******************************************************************************************/
        // Elements
        private BinaryLogFileElement _binaryLogFile;
        private W3CLogFileElement _w3CLogFile;


        /********************************************************************************************
           PROPERTIES
         *******************************************************************************************/
        /// <summary>
        /// Gets a BinaryLogFileElement that provides access to attributes relevant to the central binary log file format.
        /// </summary>
        public BinaryLogFileElement BinaryLogFile
        {
            get
            {
                return _binaryLogFile ?? (_binaryLogFile = base.GetChildElement(
                                            BinaryLogElement,
                                            typeof (BinaryLogFileElement)) as BinaryLogFileElement);
            }
        }

        /// <summary>
        /// Gets a W3cLogFileElement that provides access to attributes relevant to the central W3C log file format.
        /// </summary>
        public W3CLogFileElement W3CLogFile
        {
            get
            {
                return _w3CLogFile ?? (_w3CLogFile = base.GetChildElement(
                                             W3CLogElement,
                                             typeof (W3CLogFileElement)) as W3CLogFileElement);
            }
        }

        /// <summary>
        /// Gets or sets a LoggingMode enumeration value that provides determines the logging mode to configure.
        /// </summary>
        public LoggingMode LoggingMode
        {
            get
            {
                return (LoggingMode)base[LogModeAttribute];
            }
            set
            {
                base[LogModeAttribute] = (Int32)value;
            }
        }

        /// <summary>
        /// Gets or sets a value determining whether the logging should be done in UTF-8.
        /// </summary>
        public Boolean LogInUtf8
        {
            get
            {
                return (Boolean)base[LogInUtf8Attribute];
            }
            set
            {
                base[LogInUtf8Attribute] = value;
            }
        }
    }
}
